package com.zxx.pattern.iteratorPattern.iterator1;

import java.util.List;

/**
 * Animal集合的迭代器
 * @author zxx on 2021/3/17
 */
public class AnimalIterator implements Iterator1 {

    private List<String> animals;
    private int currentPosition;

    public AnimalIterator(List<String> animals) {
        this.animals = animals;
        this.currentPosition = -1;
    }

    @Override
    public boolean hasNext() {
        return currentPosition < animals.size() - 1;
    }

    @Override
    public Object next() {
        return animals.get(++currentPosition);
    }

}
